const { decrypt } = require("../../common/jwt");
const { jsonToString } = require("../../common/serialize");

function Authoication(target) {
    return (target, value, des) => {
        var fn = des.value;
        des.value = async (ctx, next) => {
            const { authorization } = ctx.request.header;
            if (authorization && decrypt(authorization)) {
                fn.call(this,ctx,next); 
                console.log(ctx.body)
            } else {
                ctx.status = 403;
                ctx.body = {
                    code: '403',
                    description: 'noAuthorization'
                };
            }
        }
    }
}

module.exports = Authoication;